using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;

namespace NET.Library.Web
{
    /// <summary>
    /// 
    /// </summary>
    public class Config
    {
        ///----------------------------------------------------------------------------------
        /// <summary>
        /// A helper function to retrieve config values from the configuration file
        /// and if null or empty then returns the specified default value. 
        /// </summary>
        /// <param name="configValue"></param>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static string GetConfigValue(string configValue, string defaultValue)
        {
            if (String.IsNullOrEmpty(ConfigurationManager.AppSettings[configValue]))
                return defaultValue;

            return ConfigurationManager.AppSettings[configValue];
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// A helper function to retrieve config values from the configuration file
        /// and if null or empty then returns an empty string. 
        /// </summary>
        /// <param name="configValue"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static string GetConfigValue(string configValue)
        {
            if (String.IsNullOrEmpty(ConfigurationManager.AppSettings[configValue]))
                return string.Empty;

            return ConfigurationManager.AppSettings[configValue];
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// A helper function to retrieve a connection string from the configuration file
        /// and if null or empty then returns an empty string. 
        /// </summary>
        /// <param name="connectionStringName"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static string GetConnectionString(string connectionStringName)
        {
            //Check if the connection string exists.
            if (ConfigurationManager.ConnectionStrings[connectionStringName]==null)
                return string.Empty;

            return ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;
        }
    }
}
